<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="am-g">
    <div class="am-u-md-6 am-cf">
        <div class="am-fl am-cf">
            <div class="am-btn-toolbar am-fl">
                <div class="am-btn-group am-btn-group-xs">
                    <button type="button" type="button" class="am-btn am-btn-success" onclick="add()"><span class="am-icon-plus"></span> 新增</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="am-g">
    <div class="am-u-sm-9">
            <table class="am-table am-table-striped am-table-hover table-main">
                <thead>
                <tr>
                    <th class="table-id">NO</th>
                    <th class="table-title">类型名称</th>
                    <th class="table-title">排序号</th>
                    <th class="table-set">操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${goodsTypes}" var="item" varStatus="status">
                <tr>
                    <td>${status.index+1}</td>
                    <td>${item.dicVal}</td>
                    <td>
                        ${item.sort}&nbsp;
                            <c:if test="${!status.first}">
                            <a href="javascript:sortUp('${item.id}','${item.sort}');">(<i class="am-icon-arrow-up"></i>)</a>
                            </c:if>
                            <c:if test="${!status.last}">
                            <a href="javascript:sortDown('${item.id}','${item.sort}');">(<i class="am-icon-arrow-down"></i>)</a>
                            </c:if>
                    </td>
                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="edit(${item.id})">
                                    <span class="am-icon-pencil-square-o"></span> 编辑
                                </button>
                                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger" onclick="del(${item.id})">
                                    <span class="am-icon-trash-o"></span> 删除
                                </button>
                            </div>
                        </div>
                    </td>
                </tr>
                </c:forEach>
                </tbody>
            </table>
    </div>

</div>
<script>
    function add(){
        location.href="${ctx}/admin/goodsType/add.do";
    }
    function edit(id){
        location.href="${ctx}/admin/goodsType/edit.do?id="+id;
    }
    function del(id){
        location.href="${ctx}/admin/goodsType/delete.do?pageNo=${param.pageNo}&id="+id;
    }
    function sortUp(id,sort){
        var url = "${ctx}/admin/goodsType/sortUp.do?id="+id+"&sort="+sort;
        $.get(url,function(json){
            if(json.success){
                location.reload();
            }
        },"json");
    }
    function sortDown(id,sort){
        var url = "${ctx}/admin/goodsType/sortDown.do?id="+id+"&sort="+sort;
        $.get(url,function(json){
            if(json.success){
                location.reload();
            }
        },"json");
    }
</script>